package com.cug.zfanspring.service;

import com.cug.zfanspring.bean.TransportFormat01;
import com.cug.zfanspring.bean.TransportFormat02;
import com.cug.zfanspring.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ProportionalDataService {

    @Autowired
    DeviceAlarmMapper deviceAlarmMapper;
    @Autowired
    IndexAlarmMapper indexAlarmMapper;
    @Autowired
    FactorMapper factorMapper;
    @Autowired
    DeviceMapper deviceMapper;

    public List<Map<String,Long>>  getDeviceProportionalData(){
        Map<String,Long> normal=new HashMap<>();
        Map<String,Long> fault=new HashMap<>();
     normal.put("正常",deviceAlarmMapper.getDeviceNormalNumber());
     fault.put("故障",deviceAlarmMapper.getTotalAlarms());
        List proportional=new ArrayList();
        proportional.add(normal);
        proportional.add(fault);

        return proportional;
    }
    public List<Map<String,Long>> getIndexProportionalData(){
        Map<String,Long> normal=new HashMap<>();
        Map<String,Long> fault=new HashMap<>();
        normal.put("正常",indexAlarmMapper.getIndexNormalNumber());
        fault.put("故障",indexAlarmMapper.getIndexFaultNumber());
        List proportional=new ArrayList();
        proportional.add(normal);
        proportional.add(fault);

        return proportional;
    }

    public List<TransportFormat01> getDeviceStatisticData(String area){
        TransportFormat01 normal=new TransportFormat01();
        normal.setName("正常");
        normal.setValue(deviceMapper.getDeviceNormalNumber(area));
        TransportFormat01 fault=new TransportFormat01();
        fault.setName("故障");
        fault.setValue(deviceMapper.getDeviceFaultNumber(area));
        List statistic=new ArrayList();
        statistic.add(fault);
        statistic.add(normal);
        return statistic;
    }

    public List<TransportFormat01> getFactorStatisticData(String area){
        TransportFormat01 normal=new TransportFormat01();
        normal.setName("正常");
        normal.setValue(factorMapper.getFactorNormalNumber(area));
        TransportFormat01 fault=new TransportFormat01();
        fault.setName("超标");
        fault.setValue(factorMapper.getFactorFaultNumber(area));
        List statistic=new ArrayList();
        statistic.add(fault);
        statistic.add(normal);
        return statistic;
    }


    public  Map<String,TransportFormat02> getFactorproperitesData(String area){

        TransportFormat02 ph=new TransportFormat02();
        TransportFormat02 cod=new TransportFormat02();
        TransportFormat02 tN=new TransportFormat02();
        TransportFormat02 nH3N=new TransportFormat02();
        TransportFormat02 tP=new TransportFormat02();
        Map<String,TransportFormat02> statistic=new HashMap<>();
        float PHValue,CODValue,TNValue,NH3NValue,TPValue;
        PHValue=factorMapper.getPHValue(area);
        CODValue=factorMapper.getCODValue(area);
        TNValue=factorMapper.getTNValue(area);
        NH3NValue=factorMapper.getNH3NValue(area);
        TPValue=factorMapper.getTPValue(area);
         if(PHValue>0){
             ph.setName("PH");
             ph.setValue(PHValue);
             statistic.put("ph",ph);
         }
        if(CODValue>0){
            cod.setName("COD");
            cod.setValue(CODValue);
            statistic.put("cod",cod);
        }
        if(TNValue>0){
            tN.setName("总氮");
            tN.setValue(TNValue);
            statistic.put("tN",tN);
        }
        if(NH3NValue>0){
            nH3N.setName("氨氮");
            nH3N.setValue(NH3NValue);
            statistic.put("nH3N",nH3N);
        }
        if(TPValue>0){
            tP.setName("总磷");
            tP.setValue(TPValue);
            statistic.put("tP",tP);
        }

        return statistic;
    }






}
